JWT authentication bypass via jwk header injection
This lab uses a JWT-based mechanism for handling sessions. The server supports the jwk parameter in the JWT header. This is sometimes used to embed the correct verification key directly in the token. However, it fails to check whether the provided key came from a trusted source.
To solve the lab, modify and sign a JWT that gives you access to the admin panel at /admin, then delete the user carlos.
You can log in to your own account using the following credentials: wiener:peter
The "kid" (Key ID) in a JSON Web Token (JWT) is an optional header parameter that serves as a hint to the recipient of the JWT, indicating which cryptographic key was used to sign the token. The "kid" value is a string and its specific format is not strictly defined by the JWT specification. It can be any string that uniquely identifies the key within the context of the issuer. For example, it could be a UUID, a key name, or a reference to a specific key in a key store.
https://books.spartan-cybersec.com/web/jwt/lab-5-jwt-authentication-bypass-via-jku-header-injection al decodificar el jwt con JSON WEB Tokens extension; se observa el campo kid.
- el algoritmo que utiliza es RS256 el cual esta relacionado a la encriptacion de clave publica
Headers = {
"kid": "e42a6b7f-d1fc-4434-9852-c21ce5ecead9",
"alg": "RS256"
}
Payload = {
"iss": "portswigger",
"exp": 1757201592,
"sub": "wiener"
}
Signature = "cEA-ET0xb7p2WosCn8u8zbC3Pt3LLTvvetPtXpUlca3C3ms9lih76ODPIzuaAFQLXjZYe2pnhtfPrXh6jFz9ia8ZmOssY2KaEDzjKH4ncfkE6qf8P2wKux3ADcAnMG1Kmy9Hyf-JVOlwB5QmxbYUukHRF-YT2HVciXzcb-HlI7Qijj54WPFV3kaeOBfSWOg-fmC3W76uyI-M_eleLnw9mj5_ju7X7nyORdp7oJmieWV9qBhQ8WJaJmXyaVvi8zXkofVHTI-RoyqLpjmPldiKeHihUJU60VifqO3ZnpZL-wYiXiGYPyV-zeEq4qsXmUmaPGXQdSfsuR9HWOCbBiZQCQ"
https://www.youtube.com/watch?v=t-RfzyW0iqA Luego en la sub tab de Repeater/JSON WEB TOKEN modificamos el campo sub por administrator y en la tab de JET EDITOR creamos una clave publica con "NEW RSA KEY". Despues de realizar lo anterior, te diriges a la request y en el boton inferior "Attack" eliges "Embedded JWK" y eliges la clave RSA creada, envias la request. Nuevamente asegurate de revisar hacia donde se dirige la solicitud GET, que no apunte hacia el usuario wiener.
Lo que hemos aprendido, repasado:
- JWT soporta la encriptacion con llave publica y no se limita al de clave privada
- un servidor backend mal configurado pueden utilizar cualquier llave que se le sea incorporado, en el ejercicio genere una llave RSA
- Puedo incorporar un Json Web Key (JWK) con mi llave RSA creada
- En https://www.youtube.com/watch?v=t-RfzyW0iqA menciona en el apartado de jwt_tool que puedo utilizar collaborator, pero como burp no se conecta a externos, no lo utiliza.
- Un flujo de trabajo es utilizar el JWT resultante y reemplazarlo en el browser y refrescar